/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */

package com.pig4cloud.pigx.contract.app;

import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.contract.bo.ContractExistPositionInfoBO;
import com.pig4cloud.pigx.contract.dto.AppContractMarginChangeDTO;
import com.pig4cloud.pigx.contract.dto.AppContractMultipleChangeDTO;
import com.pig4cloud.pigx.contract.service.ContractPositionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 仓位表
 *
 * @since 2022-08-11 10:08:43
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/app/position")
@Api(value = "contractposition", tags = "app仓位管理")
public class AppContractPositionController {

	private final ContractPositionService contractPositionService;

	/**
	 * 调整杠杆
	 *
	 * @param dto dto
	 * @return {@link R< Object>}
	 * @since 2022/9/21 17:14
	 */
	@ApiOperation(value = "调整杠杆", notes = "调整杠杆")
	@PostMapping("/multiple/change")
	public R<Object> multipleChange(@Validated @RequestBody AppContractMultipleChangeDTO dto) {

		contractPositionService.multipleChange(dto);

		return R.ok();
	}

	/**
	 * 逐仓调整保证金
	 *
	 * @param dto dto
	 * @return {@link R< Object>}
	 * @since 2022/9/2 14:57
	 */
	@ApiOperation(value = "逐仓调整保证金", notes = "逐仓调整保证金")
	@PostMapping("/margin/change")
	public R<Object> marginChange(@Validated @RequestBody AppContractMarginChangeDTO dto) {

		contractPositionService.marginChange(dto);

		return R.ok();
	}

	/**
	 * 查询已有仓位信息
	 *
	 * @param symbolId 币对id
	 * @return {@link R< ContractExistPositionInfoBO>}
	 * @since 2022/9/30 10:27
	 */
	@ApiOperation(value = "查询已有仓位信息", notes = "查询已有仓位信息")
	@GetMapping("/exist-info")
	public R<ContractExistPositionInfoBO> existInfo(Long symbolId) {

		ContractExistPositionInfoBO info = contractPositionService.existInfo(symbolId);

		return R.ok(info);
	}
}
